<?php

namespace App\Models\Recommend;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class ApppageRectplArea
 * @package App\Models\Recommend
 * @version July 25, 2018, 9:47 am CST
 *
 * @property \App\Models\Recommend\ApppageRectpl apppageRectpl
 * @property \App\Models\Recommend\Pagetpl pagetpl
 * @property \App\Models\Recommend\Paneltpl paneltpl
 * @property integer apppage_rectpl_id
 * @property integer pagetpl_id
 * @property integer paneltpl_id
 * @property string area
 * @property string data
 */
class ApppageRectplArea extends Model
{
    use SoftDeletes;

    public $table = 'apppage_rectpl_areas';

    protected $dates = ['deleted_at'];

    public $fillable = [
        'apppage_rectpl_id',
        'pagetpl_id',
        'paneltpl_id',
        'area',
        'data',
        'onclick',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'apppage_rectpl_id' => 'integer',
        'pagetpl_id'        => 'integer',
        'paneltpl_id'       => 'integer',
        'area'              => 'string',
        'data'              => 'string',
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        'area' => 'required|max:100',
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function apppageRectpl()
    {
        return $this->hasOne(\App\Models\Recommend\ApppageRectpl::class, 'id', 'apppage_rectpl_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function pagetpl()
    {
        return $this->hasOne(\App\Models\Application\Pagetpl::class, 'id', 'pagetpl_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function paneltpl()
    {
        return $this->hasOne(\App\Models\Application\Paneltpl::class, 'id', 'paneltpl_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * 页面推荐位位数据
     **/
    public function apppageRectplDatas()
    {
        return $this->hasMany(\App\Models\Recommend\ApppageRectplData::class, 'apppage_rectpl_area_id', 'id');
    }
}
